package com.person.leetcode.editor.cn;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

/**
  * 1417.重新格式化字符串
  * 2022-08-11 10:28:22
**/
public class Sequence_1417_ReformatTheString {
    public static void main(String[] args) {
        Solution solution = new Sequence_1417_ReformatTheString().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public String reformat(String s) {
        Queue<Character> numberQue = new LinkedList<>();
        Queue<Character> letterQue = new LinkedList<>();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (Character.isDigit(c)){
                numberQue.offer(c);
            }else{
                letterQue.offer(c);
            }
        }
        if (numberQue.size()>letterQue.size()){
            while (!numberQue.isEmpty() && !letterQue.isEmpty()) {
                sb.append(numberQue.poll()).append(letterQue.poll());
            }
                sb.append(numberQue.poll());

        }else{
            while (!numberQue.isEmpty() && !letterQue.isEmpty()){
                sb.append(letterQue.poll()).append(numberQue.poll());
            }
            if (letterQue.size()>0){
                sb.append(letterQue.poll());
            }
        }


        if (letterQue.isEmpty() && numberQue.isEmpty()){
            return sb.toString();
        }else{
            return "";
        }
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}